<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <CorporateSectorCascader
              v-if="tabsKeys != 3"
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item label="仓库" v-if="tabsKeys != 3">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.b"
                allow-clear
              >
                <a-option v-for="item in fhWhList2" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="物料编号" v-if="tabsKeys == 1 && tabsKeys != 3">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.c"
              />
            </a-form-item>
            <a-form-item label="物料名称" v-if="tabsKeys == 1 && tabsKeys != 3">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.d"
              />
            </a-form-item>
            <a-form-item label="针盘卡号" v-if="tabsKeys == 3">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.e"
              />
            </a-form-item>
          </a-form>
        </div>
        <div>
          <Toolbar
            :items="toolbarList"
            @select="selectHandler"
            @xzzp="xzzps"
            @del="delSles"
            @deletZp="deletZps"
            @export="exportExcel"
          >
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="gang"></div>
    </template>
    <template #pageTabel>
      <a-tabs
        :lazy-load="true"
        :justify="true"
        :default-active-key="tabsKeys"
        @change="tabsChanges"
      >
        <a-tab-pane title="制具仓库存查询" :key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            style="height: calc(100% - 45px)"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <a-tab-pane title="针盘列表" :key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady2"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef2"
            class="ag-theme-alpine"
            :rowData="tableDataList2"
            :columnDefs="tc2"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="fySelet.size"
            :current="fySelet.page"
          />
        </a-tab-pane>
        <a-tab-pane title="针盘使用记录" :key="3">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef3"
            class="ag-theme-alpine"
            :rowData="tableDataList3"
            :columnDefs="tc3"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet3.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize3"
            @page-size-change="change3"
            style="justify-content: center"
            :page-size="fySelet3.size"
            :current="fySelet3.page"
          />
        </a-tab-pane>
      </a-tabs>
    </template>

    <a-drawer
      :ok-text="
        dbPageDate.titles != '明细' && dbPageDate.titles != '降等报废'
          ? '保存'
          : dbPageDate.titles != '降等报废'
          ? '确定'
          : '降等'
      "
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="dbPageDate.showAdd"
      @ok="sideOk"
      placement="bottom"
      @cancel="sideNo"
    >
      <template #title>
        {{ dbPageDate.titles }}
      </template>
      <div>
        <a-form ref="formRef" :model="searchData" size="mini">
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="仓库编号">
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.warehouseCode"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="仓库名称"
                :rules="[{ required: true, message: '仓库必填' }]"
                field="warehouseName"
              >
                <a-select
                  popup-container="html"
                  v-if="
                    dbPageDate.titles != '修改针盘' &&
                    dbPageDate.titles != '明细' &&
                    dbPageDate.titles != '降等报废'
                  "
                  class="bacClass"
                  :style="{ width: '250px' }"
                  v-model="searchData.warehouseName"
                  allow-create
                  allow-search
                  @change="whChanges"
                >
                  <a-option
                    v-for="item in fhWhList"
                    :value="
                      item.id +
                      '-' +
                      item.warehouseCode +
                      '-' +
                      item.warehouseName +
                      '-' +
                      item.warehouseTypeName
                    "
                  >
                    {{ item.warehouseName }}
                  </a-option>
                </a-select>
                <a-input
                  class="bacClass"
                  v-else
                  disabled
                  v-model="searchData.warehouseName"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="生产车间"
                :rules="[{ required: true, message: '生产车间必填' }]"
                field="companyName"
              >
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.companyName"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="针盘卡号"
                :rules="[{ required: true, message: '针盘卡号必填' }]"
                field="cardNo"
              >
                <a-input
                  class="bacClass"
                  :disabled="dbPageDate.titles != '新增针盘'"
                  v-model="searchData.cardNo"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="16">
            <!-- <a-col :span="6">
            <a-form-item label-col-flex="80px" label="针筒型号" :rules="[{ required: true, message: '针筒必填' }]"
              field="workDrum">
              <a-select popup-container="html"  v-if="dbPageDate.titles != '明细' && dbPageDate.titles != '降等报废'" allow-create allow-search
                class="bacClass" :style="{ width: '250px' }" v-model="searchData.model" allow-clear
                @change="workDrumChanges">
                <a-option v-for="item in workDrumList" :value="item.model +
                  '-' +
                  item.cylinderCardNumber +
                  '-' +
                  item.sumNeedleNum +
                  '-' +
                  item.applicableModels
                  ">
                  {{ item.model }}
                </a-option>
              </a-select>
              <a-input v-else disabled class="bacClass" v-model="searchData.workDrum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label-col-flex="80px" label="针筒" :rules="[{ required: true, message: '针筒必填' }]" field="workDrum">
              <a-input disabled class="bacClass" v-model="searchData.workDrum"></a-input>
            </a-form-item>
          </a-col> -->
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="总针数"
                :rules="[{ required: true, message: '总针数必填' }]"
                field="needleNumber"
              >
                <a-input
                  disabled
                  class="bacClass"
                  v-model="searchData.needleNumber"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="适用机型"
                :rules="[{ required: true, message: '适用机型必填' }]"
                field="applyMachine"
              >
                <a-select
                  popup-container="html"
                  v-if="dbPageDate.titles != '明细' && dbPageDate.titles != '降等报废'"
                  class="bacClass"
                  :style="{ width: '250px' }"
                  v-model="searchData.applyMachine"
                  allow-clear
                  @click="machineCx1"
                  allow-create
                  allow-search
                  multiple
                >
                  <a-option v-for="item in machineTypeList1" :value="item.typeName">
                    {{ item.typeName }}
                  </a-option>
                </a-select>
                <a-input
                  v-if="dbPageDate.titles == '明细' || dbPageDate.titles == '降等报废'"
                  disabled
                  class="bacClass"
                  v-model="searchData.applyMachine"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="储位">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  :style="{ width: '250px' }"
                  v-model="searchData.storageName"
                  allow-clear
                  @click="machineCx"
                  allow-create
                  allow-search
                  :disabled="!booleanAees && dbPageDate.titles == '明细'"
                >
                  <a-option v-for="item in machineTypeList" :value="item.storageName">
                    {{ item.storageName }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="备注">
                <a-input
                  class="bacClass"
                  v-model="searchData.remark"
                  :style="{ width: '250px' }"
                ></a-input>
                <!-- <a-input class="bacClass" v-model="searchData.remark" :style="{ width: '250px' }"
                                disabled></a-input> -->
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item
                v-if="dbPageDate.titles == '明细'"
                label-col-flex="80px"
                label="机台编号"
              >
                <a-select
                  popup-container="html"
                  :disabled="booleanAees"
                  class="bacClass"
                  :style="{ width: '250px' }"
                  v-model="macObj.machineCode"
                  allow-clear
                  @click="machineNameCodeCx"
                  @change="machineNameCodeChange"
                  allow-search
                  @search="machineNameCodeCx"
                >
                  <a-option
                    v-for="item in machineNameCode"
                    :value="item.machineCode + '-' + item.machineName"
                  >
                    {{ item.machineCode + '---' + item.machineName }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                v-if="dbPageDate.titles == '明细'"
                label-col-flex="80px"
                label="机台名称"
              >
                <a-input
                  class="bacClass"
                  v-model="macObj.machineName"
                  :style="{ width: '250px' }"
                  disabled
                ></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-space style="margin-bottom: 10px">
        <a-button
          v-if="
            dbPageDate.titles != '明细' &&
            dbPageDate.titles != '降等报废' &&
            dbPageDate.titles != '修改针盘'
          "
          type="primary"
          @click="addLine"
          size="mini"
          >新增</a-button
        >
        <a-button v-if="dbPageDate.titles == '修改针盘'" type="primary" @click="addLine" size="mini"
          >加针</a-button
        >
        <a-button
          v-if="
            dbPageDate.titles != '明细' &&
            dbPageDate.titles != '降等报废' &&
            dbPageDate.titles != '修改针盘'
          "
          type="primary"
          @click="delLine"
          size="mini"
          >删除</a-button
        >
      </a-space>

      <a-table
        v-if="dbPageDate.titles == '新增针盘'"
        stripe
        :bordered="true"
        :columns="tableColumnsWl"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
        <!-- <template #materialCode="{ record }">
        <div style="width: 100%">
          <a-select popup-container="html"  class="bacClass" :allowClear="true" v-model="record.materialCode" allow-search
            @focus="focusSel2(record, 1, '')" @search="focusSel2(record, 1, $event)"
            @change="changeBh(record, record.materialCode)">
            <a-option v-for="item in pageData.wlListCode" :value="item['materialCode']">{{ item['materialCode'] + ' —— ' +
              item['materialName'] }}
            </a-option>
          </a-select>
        </div>
      </template>
      <template #materialName="{ record }">
        <div style="width: 100%">
          <a-select popup-container="html"  class="bacClass" :allowClear="true" v-model="record.materialName" allow-search
            @click="focusSel2(record, 2, '')" @search="focusSel2(record, 2, $event)"
            @change="changeWl(record, record.materialName)">
            <a-option v-for="item in wlPageDatas.wlList" :value="item['materialName']">{{ item['materialCode'] + ' —— '
              + item['materialName'] }}
            </a-option>
          </a-select>
        </div>
      </template> -->
        <template #totalNum="{ record }">
          <div style="width: 100%">
            <a-input-number
              v-model="record.totalNum"
              @change="changeTot(record)"
              class="input-demo bacClass"
              :min="0"
              :max="10000000000"
            />
          </div>
        </template>
        <!-- <template #grade="{ record }">
        <a-select popup-container="html"  @click="gradeChange" class="bacClass" v-model="record.grade" allow-clear allow-search
          @change="changeDj(record)">
          <a-option v-for="item in gradrList">{{ item.detailName }}</a-option>
        </a-select>
      </template> -->
      </a-table>
      <a-table
        v-else-if="dbPageDate.titles == '明细'"
        stripe
        :bordered="true"
        :columns="tableColumnsWl"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
      </a-table>
      <a-table
        v-if="dbPageDate.titles == '降等报废'"
        stripe
        :bordered="true"
        :columns="tableColumnsWl2"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
        <template #scrapNum="{ record }">
          <div style="width: 100%" v-if="record.grade != 'B/C'">
            <a-input-number
              @input="scrapNumInput(record)"
              v-model="record.scrapNum"
              class="input-demo bacClass"
              :min="0"
              :max="record.totalNum - record.degraNum"
            />
          </div>
        </template>
        <template #degraNum="{ record }">
          <div style="width: 100%" v-if="record.grade != 'B/C'">
            <a-input-number
              @input="degraNumInput(record)"
              v-model="record.degraNum"
              class="input-demo bacClass"
              :min="0"
              :max="record.totalNum - record.scrapNum"
            />
          </div>
        </template>
        <template #degraded="{ record }">
          <a-select
            popup-container="html"
            v-if="record.grade != 'B/C'"
            @click="gradeChange2(record)"
            class="bacClass"
            v-model="record.degraded"
            allow-clear
          >
            <a-option v-for="item in gradrList2">{{ item }}</a-option>
          </a-select>
        </template>
      </a-table>
      <a-table
        v-if="dbPageDate.titles == '修改针盘'"
        stripe
        :bordered="true"
        :columns="tableColumnsWlA"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
        <template #subNum="{ record }">
          <div style="width: 100%">
            <a-input-number
              v-model="record.subNum"
              @change="changeTotA(record)"
              class="input-demo bacClass"
              :min="0"
              :max="record.totalNum"
            />
          </div>
        </template>
        <template #addNum="{ record }">
          <div style="width: 100%">
            <a-input-number
              v-model="record.addNum"
              class="input-demo bacClass"
              :min="0"
              :max="record.totalNum1 - record.useNum"
            />
          </div>
        </template>
      </a-table>
      <a-table
        v-if="dbPageDate.titles == '修改针盘' || dbPageDate.titles == '新增针盘'"
        stripe
        :bordered="true"
        :columns="tableColumnsWl1"
        size="mini"
        :data="wlListArray1"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="id"
        v-model:selected-keys="selectedRowKeysWl"
        style="margin-top: 40px"
      >
      </a-table>
    </a-drawer>
    <a-drawer
      ok-text="保存补针"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="dbPageDate.showAdd2"
      @ok="sideOk2"
      placement="bottom"
      @cancel="sideNo2"
    >
      <template #title> 补针 </template>
      <div>
        <a-form ref="formRef" :model="searchData" size="mini">
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="仓库编号">
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.warehouseCode"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="仓库名称"
                :rules="[{ required: true, message: '仓库必填' }]"
                field="warehouseName"
              >
                <a-input class="bacClass" disabled v-model="searchData.warehouseName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="生产车间"
                :rules="[{ required: true, message: '生产车间必填' }]"
                field="companyName"
              >
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.companyName"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :span="6">
            <a-form-item label-col-flex="80px" label="针筒" :rules="[{ required: true, message: '针筒必填' }]" field="workDrum">
              <a-input disabled class="bacClass" v-model="searchData.workDrum"></a-input>
            </a-form-item>
          </a-col> -->
          </a-row>
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="总针数"
                :rules="[{ required: true, message: '总针数必填' }]"
                field="needleNumber"
              >
                <a-input
                  disabled
                  class="bacClass"
                  v-model="searchData.needleNumber"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="适用机型"
                :rules="[{ required: true, message: '适用机型必填' }]"
                field="applyMachine"
              >
                <a-input disabled class="bacClass" v-model="searchData.applyMachine"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="备注">
                <a-input
                  class="bacClass"
                  v-model="searchData.remark"
                  :style="{ width: '250px' }"
                  disabled
                ></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        stripe
        :bordered="true"
        :columns="tableColumnsWl3"
        size="mini"
        :data="wlListArray3"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        v-model:selected-keys="selectedRowKeysWl"
      >
        <template #alite="{ record }">
          <a-button
            @click="clickBC(record)"
            v-if="record.grade == 'B/C'"
            type="primary"
            status="success"
            >补针</a-button
          >
          <a-button v-else type="primary" status="success" disabled>补针</a-button>
        </template>
      </a-table>
    </a-drawer>

    <a-modal
      fullscreen
      v-model:visible="visible"
      :mask-closable="false"
      :on-before-ok="handleOk"
      @cancel="handleCancel"
    >
      <template #title> 补针 </template>
      <div :style="{ marginBottom: '10px' }">
        <a-button @click="addLineMcode" type="primary">新增</a-button>
      </div>
      <a-table
        stripe
        :bordered="true"
        :columns="tableColumnsWl4"
        :data="wlListArray4"
        :pagination="false"
      >
        <template #grade="{ record }">
          <a-select
            popup-container="html"
            @click="gradeChange3"
            class="bacClass"
            v-model="record.grade"
            allow-clear
            allow-search
            @change="changeDj(record)"
          >
            <a-option v-for="item in gradrList3">{{ item }}</a-option>
          </a-select>
        </template>
        <template #delet="{ record }">
          <a-button @click="delLine2(record)" type="primary">删除</a-button>
        </template>
        <template #totalNum="{ record }">
          <a-input-number
            v-if="
              record['totalNum1'] != undefined &&
              record['totalNum1'] != null &&
              record['totalNum1'] != ''
            "
            class="bacClass"
            v-model="record.totalNum"
            :max="record['totalNum1'] - record['useNum']"
            :min="0"
          ></a-input-number>
          <a-input-number v-else :min="0" disabled></a-input-number>
        </template>
      </a-table>
    </a-modal>

    <!-- 归还弹窗 -->
    <a-drawer
      ok-text="入库"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      :height="'100%'"
      :visible="dbPageDate.showAdd3"
      @ok="sideOk3"
      placement="bottom"
      @cancel="sideNo3"
    >
      <template #title>针盘入库</template>
      <div>
        <a-form ref="formRef" :model="searchData" size="mini">
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="仓库编号">
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.warehouseCode"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="仓库名称"
                :rules="[{ required: true, message: '仓库必填' }]"
                field="warehouseName"
              >
                <a-input class="bacClass" disabled v-model="searchData.warehouseName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="生产车间"
                :rules="[{ required: true, message: '生产车间必填' }]"
                field="companyName"
              >
                <a-input
                  class="bacClass"
                  disabled
                  v-model="searchData.companyName"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :span="6">
            <a-form-item label-col-flex="80px" label="针筒" :rules="[{ required: true, message: '针筒必填' }]" field="workDrum">
              <a-input disabled class="bacClass" v-model="searchData.workDrum"></a-input>
            </a-form-item>
          </a-col> -->
          </a-row>
          <a-row :gutter="16">
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="总针数"
                :rules="[{ required: true, message: '总针数必填' }]"
                field="needleNumber"
              >
                <a-input
                  disabled
                  class="bacClass"
                  v-model="searchData.needleNumber"
                  :style="{ width: '250px' }"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="80px"
                label="适用机型"
                :rules="[{ required: true, message: '适用机型必填' }]"
                field="applyMachine"
              >
                <a-input disabled class="bacClass" v-model="searchData.applyMachine"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label-col-flex="80px" label="备注">
                <a-input
                  class="bacClass"
                  v-model="searchData.remark"
                  :style="{ width: '250px' }"
                  disabled
                ></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        stripe
        :bordered="true"
        :columns="tableColumnsWl"
        size="mini"
        :data="wlListArray"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        rowKey="typeIds"
        v-model:selected-keys="selectedRowKeysWl"
      >
      </a-table>
    </a-drawer>

    <a-modal
      fullscreen
      v-model:visible="visibleYlzj"
      :on-before-ok="handleOkszj"
      @cancel="() => (visibleYlzj = false)"
      :mask-closable="false"
    >
      <template #title>制具仓库存</template>
      <div class="cgisDatas">
        <div>
          <span>物料编号:</span>
          <a-input
            class="bacClass"
            v-model="isLyCodedsZp"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <div>
          <span>物料名称:</span>
          <a-input
            class="bacClass"
            v-model="isLyNamedsZp"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <a-button type="primary" size="mini" @click="cxZpKc">查询</a-button>
      </div>
      <a-table
        :style="{
          height: '500px',
          marginTop: '10px',
        }"
        :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
        rowKey="id"
        v-model:selected-keys="selectedRowKeysZp"
        stripe
        :bordered="true"
        :scrollbar="true"
        sticky-header
        :pagination="false"
        :columns="cgColumnsZp"
        :data="wlListZp"
      >
      </a-table>
      <paginationCopys
        :page-size-options="pagingList1"
        :total="fySeletZp.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSizeZp"
        @page-size-change="changeZp"
        style="justify-content: center; margin-top: 20px"
        :page-size="fySeletZp.size"
        :current="fySeletZp.page"
      />
    </a-modal>
    <a-modal
      :visible="qrData.QRcodeVisible"
      @ok="printQRcode"
      @cancel="qRcodeCancel"
      okText="打印"
      cancelText="关闭"
      unmountOnClose
      width="400px"
    >
      <template #title> 打印二维码</template>
      <div id="qrcodebox" style="width: 100%; display: flex; align-items: center">
        <QrcodeVue :value="qrData.code"></QrcodeVue>
        <div class="ml-5"
          ><p style="white-space: nowrap; width: 250px">针盘卡号:{{ qrData.cardNo }}</p
          ><p style="white-space: nowrap; width: 250px">总针数:{{ qrData.needleNumber }}</p></div
        >
      </div>
    </a-modal>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ref, reactive, h } from 'vue'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'
  
  import Toolbar from '@/components/Toolbar.vue'
  import { exportJsonToExcel } from '@/api/Export2Excel'
  import { exportStyleExcel } from '@/api/Export2StyleExcel'
  import printJS from 'print-js'
  import QrcodeVue from 'qrcode.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import WHService from '@/service/wh'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import usePermission from '@/store/modules/permission'
  import { pagingList } from '@/api/paging'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()

  const whService = new WHService()
  const qrData: any = ref({
    QRcodeVisible: false,
    code: '',
  })
  const printQRcode = () => {
    printJS({
      printable: 'qrcodebox',
      type: 'html',
      targetStyles: ['*'],
    })
    visible.value = false
  }
  const qRcodeCancel = () => {
    qrData.value.QRcodeVisible = false
    qrData.value.code = ''
  }
  const openQRCode = (code: any, needleNumber: string, cardNo: string) => {
    qrData.value.code = JSON.stringify(code)
    qrData.value.QRcodeVisible = true
    qrData.value.needleNumber = needleNumber
    qrData.value.cardNo = cardNo
  }
  const fhWhList: any = whService.whList

  const headerShow = ref(true)
  const localeText1: any = ref(localeText)

  const tabsKeys = ref(1)

  const toolbarList: any = ref([
    `${permissionStore.hasPermisson('zjckc.zjckccxcx') ? '查询' : ''}`,
    '导出',
  ])

  const dbPageDate: any = reactive({
    showAdd: false,
    showAdd2: false,
    showAdd3: false,
    titles: '新增针盘',
  })

  const tabsChanges = (e: any) => {
    tabsKeys.value = e
    if (tabsKeys.value == 1) {
      fySelet2.page = 1
      wjYcList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjckc.zjckccxcx') ? '查询' : ''}`,
        '导出',
      ]
    } else if (tabsKeys.value == 2) {
      fySelet.page = 1
      zpCxList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjckc.zplbxz') ? '新增针盘' : ''}`,
        `${permissionStore.hasPermisson('zjckc.zplbcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('zjckc.zplbqkzp') ? '清空针盘' : ''}`,
        `${permissionStore.hasPermisson('zjckc.zplbsc') ? '删除' : ''}`,
      ]
    } else if (tabsKeys.value == 3) {
      fySelet3.page = 1
      zpCxList2()
      toolbarList.value = ['查询']
    }
  }
  onMounted(() => {
    updateGridState01()
    updateGridState02()
    updateGridState03()
    wjYcList()
  })
  const pageData: any = reactive({
    a: '',
    b: '',
    c: '',
    d: '',
    e: '',
    wlListCode: [],
  })

  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      fySelet2.page = 1
      wjYcList()
    } else if (tabsKeys.value == 2) {
      fySelet.page = 1
      zpCxList()
    } else if (tabsKeys.value == 3) {
      fySelet3.page = 1
      zpCxList2()
    }
  }
  const tableDataList: any = ref([])
  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }
  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const fySelet3: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize3 = (val: any) => {
    fySelet3.page = val
    zpCxList2()
  }

  const change3 = (val: any) => {
    fySelet3.size = val
    zpCxList2()
  }

  const fySelet2: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize2 = (val: any) => {
    fySelet2.page = val
    wjYcList()
  }

  const change2 = (val: any) => {
    fySelet2.size = val
    wjYcList()
  }
  const fySelet: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet.page = val
    zpCxList()
  }

  const change = (val: any) => {
    fySelet.size = val
    zpCxList()
  }

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'companyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '仓库类型名称',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '可用库存',
      field: 'availableNum',
      width: 150,
    },
    {
      headerName: '针盘使用数量',
      field: 'useNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
  ]

  const tableDataList2: any = ref([])
  const gridOption2 = ref()
  const colState2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState2.value = params.columnApi
  }
  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const tableDataList3: any = ref([])
  const gridOption3 = ref()
  const colState3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
    colState3.value = params.columnApi
  }
  const defaultColDef3 = {
    sortable: true,
    resizable: true,
    filter: true,
    flex: 1,
  }
  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'companyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '仓库类型名称',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    // {
    //   headerName: '状态',
    //   field: 'emptyState',
    //   width: 150,
    //   cellRenderer: {
    //     template: `<span>{{states == 0 ? '针盘已清空' : ''}}</span>`,
    //     setup(props: any) {
    //       return {
    //         states: props.params.data.emptyState,
    //       }
    //     },
    //   },
    // },
    {
      headerName: '针盘卡号',
      field: 'cardNo',
      width: 150,
    },
    {
      headerName: '适用机型',
      field: 'applyMachine',
      width: 150,
    },
    // {
    //   headerName: '针筒',
    //   field: 'workDrum',
    //   width: 150,
    // },
    // {
    //   headerName: '适用机型',
    //   field: 'typeName',
    //   width: 150,
    // },
    {
      headerName: '储位',
      field: 'storageName',
      width: 150,
    },
    {
      headerName: '总针数',
      field: 'needleNumber',
      width: 150,
    },
    {
      headerName: '是否借出',
      field: 'debitState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `<span>{{states == 0 ? '否' :states == 1?'是':''}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.debitState,
          }
        },
      },
    },
    {
      headerName: '操作',
      field: 'atous',
      pinned: 'right',
      width: 400,
      cellRenderer: {
        template: `<a-space>
                <a-button @click="a" v-if="z" type="primary">修改</a-button>
                <a-button @click="b" v-if="states.debitState == 0 && z1" type="primary" status="success">借出</a-button>
                <a-button @click="g" v-else-if="z1" type="primary" status="danger">归还</a-button>
                <a-button @click="c" v-if="states.debitState == 0 && states.lendNum != 0 && z2" type="primary" status="danger">降等报废</a-button>
                <a-button v-else-if="z2" type="primary" status="danger" disabled>降等报废</a-button>
                <a-button @click="d" v-if="states.debitState == 0 &&states.lendNum != 0 && z3" status="success">补针</a-button>
                <a-button v-else-if="z3" type="primary" status="success" disabled>补针</a-button>
                <a-button type="outline" v-if="z4" @click="h">二维码</a-button>
                <a-button type="outline" disabled v-else>二维码</a-button>
                </a-space>
            `,
        setup(props: any) {
          const a = () => {
            updataList(props.params.data)
          }
          const b = () => {
            mxList(props.params.data)
          }
          const c = () => {
            mxList2(props.params.data)
          }
          const d = () => {
            mxList3(props.params.data)
          }
          const g = () => {
            mxList4(props.params.data)
          }
          const h = () => {
            openQRCode(
              {
                cardNo: props.params.data.cardNo,
                id: props.params.data.id,
              },
              props.params.data.needleNumber,
              props.params.data.cardNo
            )
          }
          return {
            a,
            b,
            c,
            d,
            g,
            h,
            states: props.params.data,
            z: permissionStore.hasPermisson('zjckc.zplbxg'),
            z1: permissionStore.hasPermisson('zjckc.zplbjc'),
            z2: permissionStore.hasPermisson('zjckc.zplbcfjd'),
            z3: permissionStore.hasPermisson('zjckc.zplbbz'),
            z4: permissionStore.hasPermisson('zjckc.zpewmdy'),
          }
        },
      },
    },
    {
      headerName: '创建人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '修改人',
      field: 'updateName',
      width: 150,
    },
    {
      headerName: '修改时间',
      field: 'updateTime',
      width: 150,
    },
  ]

  const tc3 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'firmName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '针盘卡号',
      field: 'cardNo',
      width: 150,
    },
    {
      headerName: '机台编号',
      field: 'machineCode',
      width: 150,
    },
    {
      headerName: '机台名称',
      field: 'machineName',
      width: 150,
    },
    {
      headerName: '是否借出',
      field: 'infoType',
      width: 150,
      cellRenderer: {
        template: `<span>{{states == 0 ? '借出' : '归还'}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.infoType,
          }
        },
      },
    },
    {
      headerName: '操作时间',
      field: 'lendReturnTime',
      width: 150,
    },
    {
      headerName: '操作人',
      field: 'createName',
      width: 150,
    },
  ]
  const clickHs = (data: any) => {
    console.log
  }
  const wjYcList = () => {
    post({
      url: 'wms/toolStockSummary/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        materialCode: pageData.c,
        materialName: pageData.d,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b == '' ? null : pageData.b,
      },
    }).then((res: any) => {
      gridOption.value.setRowData(res.data.data)
      setTableTotalRow(gridOption, res.data.data, ['totalNum', 'availableNum', 'useNum'])
      tableDataList.value = res.data.data
      fySelet2.total = res.data.total
    })
  }

  const zpCxList = () => {
    post({
      url: 'wms/toolVessel/getPlatterPage',
      data: {
        page: fySelet.page,
        size: fySelet.size,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b == '' ? null : pageData.b,
      },
    }).then((res: any) => {
      gridOption2.value.setRowData(res.data.data)
      tableDataList2.value = res.data.data
      fySelet.total = res.data.total
    })
  }
  const zpCxList2 = () => {
    post({
      url: 'wms/toolVesselDebit/getPageDebit',
      data: {
        page: fySelet3.page,
        size: fySelet3.size,
        cardNo: pageData.e,
      },
    }).then((res: any) => {
      gridOption3.value.setRowData(res.data.data)
      tableDataList3.value = res.data.data
      fySelet3.total = res.data.total
    })
  }

  const xzzps = async () => {
    const resq = await post({
      url: 'wms/toolVesselCode/addCardNo',
    })
    if (resq.code == 200) {
      searchData.cardNo = resq.data
    } else {
      Message.error(resq.message)
    }
    const res = await post({
      url: 'admin/acl/user/findUserToken',
    })
    if (res.code == 200) {
      whService.getWarhouseListByFirmId(res.data.data.firmId, '制具仓')
      workDrumCx(res.data.data.firmId)
      searchData.companyId = res.data.data.firmId
      searchData.companyName = res.data.data.firmName
      wlListArray1.value = []
      dbPageDate.titles = '新增针盘'
      dbPageDate.showAdd = true
      wlListArray.value.forEach(function (o: any) {
        getTotalNum(o)
      })
    }
  }

  const formRef: any = ref()

  const sideOk = async () => {
    for (let i = 0; i < wlListArray.value.length; i++) {
      if (
        wlListArray.value[i].grade == '' ||
        wlListArray.value[i].grade == null ||
        wlListArray.value[i].grade == undefined
      ) {
        Message.error('等级必填')
        return
      }
    }
    for (let i = 0; i < wlListArray.value.length; i++) {
      // if (!wlListArray.value[i].totalNum) {
      //   Message.error('数量必须>0')
      //   return
      // }
      // if (wlListArray.value[i].totalNum + wlListArray.value[i].addNum <= wlListArray.value[i].subNum) {
      //   Message.error('数量必须>0')
      //   return false
      // }
      if (wlListArray.value[i].degraded && !wlListArray.value[i].degraNum) {
        Message.error('降等数量必须>0')
        return
      }
    }
    formRef.value?.validate().then((err: any) => {
      if (!err) {
        if (dbPageDate.titles == '新增针盘') {
          if (wlListArray.value.length == 0) {
            Message.warning({
              content: '请新增至少一条物料信息',
              duration: 5000,
            })
            return
          }
          searchData.applyMachine = searchData.applyMachine.join()
          post({
            url: 'wms/toolVessel/addDial',
            data: {
              toolVessel: { ...searchData },
              detail: wlListArray.value,
            },
          }).then(({ code, message }) => {
            if (code == 200) {
              zpCxList()
              for (let item in searchData) {
                searchData[item] = null
              }
              wlListArray.value = []
              deleteInfo.value = []
              dbPageDate.showAdd = false
              Message.success('成功')
            } else {
              searchData.applyMachine = searchData.applyMachine.split(',')
              Message.error(message)
            }
          })
        } else if (dbPageDate.titles == '修改针盘') {
          searchData.applyMachine = searchData.applyMachine.join()
          post({
            url: 'wms/toolVessel/untie',
            data: {
              toolVessel: { ...searchData },
              updateInfo: wlListArray.value,
              deleteInfo: deleteInfo.value,
            },
          }).then(({ code, message }) => {
            if (code == 200) {
              zpCxList()
              for (let item in searchData) {
                searchData[item] = null
              }
              wlListArray.value = []
              deleteInfo.value = []
              dbPageDate.showAdd = false
              Message.success('成功')
            } else {
              searchData.applyMachine = searchData.applyMachine.split(',')
              Message.error(message)
            }
          })
        } else if (dbPageDate.titles == '明细') {
          if (booleanAees.value) {
            formRef.value?.validate().then((err: any) => {
              if (!err) {
                // searchData.applyMachine = searchData.applyMachine.join()
                if (searchData.storageName == null) searchData.storageName = ''
                post({
                  url: 'wms/toolInStock/returnInStock',
                  data: {
                    stockInfo: {
                      inStockType: '车间退料入库',
                      // companyId: searchData.companyId,
                      // companyName: searchData.companyName,
                      // warehouseTypeName: searchData.warehouseTypeName,
                      // warehouseId: searchData.warehouseId,
                      // warehouseName: searchData.warehouseName,
                      // vesselsId: macObj.vesselId
                      ...macObj,
                      ...searchData,
                    },
                    addInfo: wlListArray.value,
                    deleteInfo: deleteInfo.value,
                  },
                }).then(({ code, message }) => {
                  if (code == 200) {
                    zpCxList()
                    for (let item in searchData) {
                      searchData[item] = null
                    }
                    for (let item in macObj) {
                      macObj[item] = null
                    }
                    wlListArray.value = []
                    deleteInfo.value = []
                    dbPageDate.showAdd = false
                    Message.success('成功')
                  } else {
                    // searchData.applyMachine = searchData.applyMachine.split(",")
                    Message.error(message)
                  }
                })
              }
            })
          } else {
            if (
              macObj.machineName == '' ||
              macObj.machineName == null ||
              macObj.machineName == undefined
            ) {
              Message.error('机台必选')
              return
            }
            macObj['storageName'] = searchData.storageName == null ? '' : searchData.storageName
            post({
              url: 'wms/toolOutStock/addDiscOutStock',
              data: macObj,
            }).then((res: any) => {
              if (res.code == 200) {
                for (let item in searchData) {
                  searchData[item] = null
                }
                for (let item in macObj) {
                  macObj[item] = null
                }
                zpCxList()
                wlListArray.value = []
                deleteInfo.value = []
                dbPageDate.showAdd = false
                Message.success('成功')
              } else {
                Message.error(res.message)
              }
            })
          }
        } else if (dbPageDate.titles == '降等报废') {
          // wlListArray.value.forEach((o: any) => {
          //     if(o['scrapNum']){
          //         o['totalNum'] = o['totalNum'] - o['scrapNum']
          //     }
          // })
          post({
            url: 'wms/toolVessel/untieDegraded',
            data: {
              toolVessel: { ...searchData },
              rowInfo: wlListArray.value,
            },
          }).then((res: any) => {
            if (res.code == 200) {
              for (let item in searchData) {
                searchData[item] = null
              }
              for (let item in macObj) {
                macObj[item] = null
              }
              zpCxList()
              wlListArray.value = []
              deleteInfo.value = []
              dbPageDate.showAdd = false
              Message.success('成功')
            } else {
              Message.error(res.message)
            }
          })
        }
      }
    })
  }
  const sideNo = () => {
    wlListArray.value = []
    deleteInfo.value = []
    dbPageDate.showAdd = false
    for (let item in searchData) {
      searchData[item] = ''
    }
    macObj.machineCode = ''
    macObj.machineName = ''
  }

  const searchData: any = reactive({
    companyName: '',
    companyId: '',
    warehouseTypeName: '',
    warehouseId: null,
    warehouseName: '',
    warehouseCode: '',
    applyMachine: '',
    workDrum: '',
    needleNumber: null,
    model: '', //型号
    remark: '',
    cardNo: '', //针盘卡号
    storageName: '',
  })

  let typeIds = 0
  const addLine = () => {
    if (!searchData.warehouseId) {
      Message.warning('请选择仓库')
      return false
    }
    // wlListArray.value.push({
    //   typeIds: typeIds++,
    //   materialCode: '',
    //   unit: '',
    //   materialName: '',
    //   totalNum: 0,
    //   totalNum1: 0,
    // })
    isLyCodedsZp.value = ''
    isLyNamedsZp.value = ''
    selectedRowKeysZp.value = []
    wlListZp.value = []
    visibleYlzj.value = true
  }

  const deleteInfo: any = ref([])

  const delLine = () => {
    if (selectedRowKeysWl.value.length === 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }
    selectedRowKeysWl.value.forEach((e: any) => {
      wlListArray.value.forEach((o: any) => {
        if (o.typeIds == e) {
          if (o.id != undefined || o.id != null) {
            deleteInfo.value.push(o.id)
          }
        }
      })
    })
    wlListArray.value = wlListArray.value.filter(function (o: any, index: any) {
      return selectedRowKeysWl.value.indexOf(o['typeIds']) === -1
    })
  }

  const whChanges = (e: any) => {
    searchData.warehouseId = Number(e.split('-')[0])
    searchData.warehouseCode = e.split('-')[1]
    searchData.warehouseName = e.split('-')[2]
    searchData.warehouseTypeName = e.split('-')[3]
  }

  const selectedRowKeysWl: any = ref([])

  const wlListArray: any = ref([])
  const wlListArray1: any = ref([])
  const tableColumnsWl: any = [
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      slotName: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
      slotName: 'grade',
    },
    {
      title: '库存数量',
      key: 'totalNum1',
      dataIndex: 'totalNum1',
      width: 150,
    },
    {
      title: '已使用数量',
      key: 'useNum',
      dataIndex: 'useNum',
      width: 150,
    },
    {
      title: '数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
    },
  ]
  const tableColumnsWlA: any = [
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      slotName: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
      slotName: 'grade',
    },
    {
      title: '库存数量',
      key: 'totalNum1',
      dataIndex: 'totalNum1',
      width: 150,
    },
    {
      title: '已使用数量',
      key: 'useNum',
      dataIndex: 'useNum',
      width: 150,
    },
    {
      title: '数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
    },
    {
      title: '拆分数量',
      key: 'subNum',
      dataIndex: 'subNum',
      width: 150,
      slotName: 'subNum',
    },
    {
      title: '加针数量',
      key: 'addNum',
      dataIndex: 'addNum',
      width: 150,
      slotName: 'addNum',
    },
  ]
  const tableColumnsWl1: any = [
    {
      title: '机台',
      key: 'machineCode',
      dataIndex: 'machineCode',
      width: 150,
    },
    {
      title: '借出日期',
      key: 'lendTime',
      dataIndex: 'lendTime',
      width: 150,
    },
    {
      title: '归还日期',
      key: 'returnTime',
      dataIndex: 'returnTime',
      width: 150,
    },
    {
      title: '使用时间',
      key: 'useTime',
      dataIndex: 'useTime',
      width: 150,
    },
  ]
  const tableColumnsWl2: any = [
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      slotName: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      title: '库存数量',
      key: 'totalNum1',
      dataIndex: 'totalNum1',
      width: 150,
    },
    {
      title: '已使用数量',
      key: 'useNum',
      dataIndex: 'useNum',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '原等级',
      width: 150,
      slotName: 'grade',
      fixed: 'right',
    },
    {
      dataIndex: 'degraded',
      key: 'degraded',
      title: '降等级',
      width: 150,
      slotName: 'degraded',
      fixed: 'right',
    },
    {
      title: '原数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
      fixed: 'right',
    },
    {
      title: '降等数量',
      key: 'degraNum',
      dataIndex: 'degraNum',
      width: 150,
      slotName: 'degraNum',
      fixed: 'right',
    },
    {
      title: '报废数量',
      key: 'scrapNum',
      dataIndex: 'scrapNum',
      width: 150,
      slotName: 'scrapNum',
      fixed: 'right',
    },
    // {
    //     title: "操作",
    //     key: "solte",
    //     dataIndex: "solte",
    //     width: 100,
    //     slotName: 'solte',
    //     fixed: 'right',
    // }
  ]

  const tableColumnsWl3: any = [
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      slotName: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
      slotName: 'grade',
    },
    {
      title: '库存数量',
      key: 'totalNum1',
      dataIndex: 'totalNum1',
      width: 150,
    },
    {
      title: '已使用数量',
      key: 'useNum',
      dataIndex: 'useNum',
      width: 150,
    },
    {
      title: '数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
    },
    {
      title: '操作',
      key: 'alite',
      dataIndex: 'alite',
      width: 150,
      slotName: 'alite',
      fixed: 'alite',
    },
  ]

  const tableColumnsWl4: any = [
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      slotName: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
    {
      title: '库存数量',
      key: 'totalNum1',
      dataIndex: 'totalNum1',
      width: 150,
    },
    {
      title: '已使用数量',
      key: 'useNum',
      dataIndex: 'useNum',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
      slotName: 'grade',
      fixed: 'right',
    },
    {
      title: '数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
      fixed: 'right',
    },
    {
      dataIndex: 'delet',
      key: 'delet',
      title: '操作',
      width: 150,
      slotName: 'delet',
      fixed: 'right',
    },
  ]

  const wlPageDatas: any = reactive({
    wlList: [],
  })

  const focusSel2 = (record: any, num: any, strings: any) => {
    let ob = {}
    if (num == 1) {
      ob['warehouseId'] = searchData.warehouseId
      ob['materialCode'] = strings
    } else {
      ob['warehouseId'] = searchData.warehouseId
      ob['materialName'] = strings
    }
    post({
      url: 'wms/toolStockSummary/getMaterialInfoWms',
      data: ob,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        if (num == 1) {
          pageData.wlListCode = data
        } else {
          wlPageDatas.wlList = data
        }
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const changeWl = (record: any, val: any) => {
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialName'] == record['materialName']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialName'] == val
    })
    if (list.length > 0) {
      record['materialCode'] = list[0]['materialCode']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
    }
    getTotalNum(record)
  }
  //物料编号改变 拿到物料名称
  function changeBh(record: any, val: any) {
    console.log(wlListArray.value)

    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialCode'] == record['materialCode']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }

    let list = pageData.wlListCode.filter(function (o: any) {
      return o['materialCode'] == val
    })
    if (list.length > 0) {
      record['materialName'] = list[0]['materialName']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
    }
    getTotalNum(record)
  }
  function changeDj(record: any) {
    getTotalNum(record)
  }
  //拿到库存数量
  function getTotalNum(record: any) {
    post({
      url: 'wms/toolStockSummary/getToolsStockNum',
      data: {
        materialCode: record['materialCode'],
        grade: record['grade'],
        warehouseId: searchData.warehouseId,
      },
    }).then(({ code, data }) => {
      if (code === 200) {
        console.log(data)
        record['totalNum1'] = data['totalNum']
        record['useNum'] = data['useNum']
      }
    })
  }
  const gradrList: any = ref([])

  const gradeChange = () => {
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }

  const gradrList2: any = ref([])

  const gradeChange2 = (record: any) => {
    post({
      url: 'dict/dictTypeDetail/getListByMapGrade',
      data: {
        codeType: 36,
        detailName: record.grade,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList2.value = data
      }
    })
  }

  const workDrumList: any = ref([])

  const workDrumCx = (id: any) => {
    post({
      url: 'product/workdrumEquipment/getFieldValueWms',
      data: {
        companyId: id,
        cylinderCardNumber: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        workDrumList.value = data
      }
    })
  }
  const workDrumChanges = (e: any) => {
    searchData.model = e.split('-')[0]
    searchData.workDrum = e.split('-')[1]
    searchData.needleNumber = e.split('-')[2]
    searchData.applyMachine = e.split('-')[3]
  }
  // planSingle/machineType/getFieldValue{typeName: ""}\
  const machineTypeList: any = ref([])
  const machineTypeList1: any = ref([])
  const machineCx = () => {
    if (
      searchData.warehouseName == '' ||
      searchData.warehouseName == null ||
      searchData.warehouseName == undefined
    ) {
      Message.error('请先选择仓库!')
      // return
    } else {
      let ob = ''
      if (dbPageDate.titles == '新增针盘') {
        // console.log(fhWhList.value, '2')
        fhWhList.value.forEach((item: any) => {
          if (item.warehouseName == searchData.warehouseName) {
            return (ob = item.id)
          }
        })
      } else {
        ob = gridOption2.value.getSelectedRows()[0].warehouseId
      }
      // if (!e||typeof e === 'object') {
      //   e=''
      // }
      let params = {
        warehouseId: ob,
        // storageName:e
      }
      post({
        url: 'wms/Storage/getStorageByPara',
        data: params,
      }).then(({ data, code, message }: any) => {
        if (code === 200) {
          machineTypeList.value = data
        } else {
          Message.error(message)
        }
      })
    }
  }
  const machineCx1 = () => {
    post({
      url: 'planSingle/machineType/getFieldValue',
      data: {
        typeName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        machineTypeList1.value = data
      }
    })
  }

  const updataList = (e: any) => {
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code, message }: any) => {
      if (code === 200) {
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        searchData.applyMachine = searchData.applyMachine.split(',')
        data.details.forEach((res: any) => {
          wlListArray.value.push({
            typeIds: typeIds++,
            ...res,
          })
        })
        wlListArray.value.forEach(function (o: any) {
          getTotalNum(o)
        })
        postTwoList(wlListArray.value)
        dbPageDate.titles = '修改针盘'
        wlListArray1.value = []
        searchData.needleNumber = 0
        wlListArray.value.forEach((res: any) => {
          searchData.needleNumber += res.totalNum
          res.addNum = 0
          res.subNum = 0
        })
        dbPageDate.showAdd = true
      } else {
        Message.error(message)
      }
    })
  }

  const delSles = () => {
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        post({
          url: 'wms/toolVessel/delete',
          data: gridOption2.value.getSelectedRows().map((res: any) => res.id),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('删除成功')
            zpCxList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const mxList = (e: any) => {
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        // searchData.applyMachine = searchData.applyMachine.split(",")
        data.details.forEach((res: any) => {
          wlListArray.value.push({
            typeIds: typeIds++,
            ...res,
          })
        })
        macObj.vesselId = e.id
        macObj.companyId = e.companyId
        dbPageDate.titles = '明细'
        booleanAees.value = false
        dbPageDate.showAdd = true
        searchData.needleNumber = 0
        wlListArray.value.forEach(function (o: any) {
          getTotalNum(o)
          searchData.needleNumber += o.totalNum
        })
      }
    })
  }

  const mxList2 = (e: any) => {
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        data.details.forEach((res: any) => {
          wlListArray.value.push({
            scrapNum: 0,
            degraNum: 0,
            typeIds: typeIds++,
            ...res,
          })
        })
        macObj.vesselId = e.id
        macObj.companyId = e.companyId
        dbPageDate.titles = '降等报废'
        dbPageDate.showAdd = true
        searchData.needleNumber = 0
        wlListArray.value.forEach(function (o: any) {
          getTotalNum(o)
          searchData.needleNumber += o.totalNum
        })
      }
    })
  }

  const wlListArray3: any = ref([])

  const mxList3 = (e: any) => {
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        getZpId = e.id
        wlListArray3.value = data.details
        dbPageDate.showAdd2 = true
        searchData.needleNumber = 0
        wlListArray3.value.forEach((item: any) => {
          searchData.needleNumber += item.totalNum
        })
      }
    })
  }
  const booleanAees: boolean = ref(false)
  const mxList4 = (e: any) => {
    // post({
    //   url: 'wms/toolVessel/getDetails',
    //   data: {
    //     id: e.id
    //   }
    // }).then(({ data, code }: any) => {
    //   if (code === 200) {
    //     for (let i in data.toolVessel) {
    //       searchData[i] = data.toolVessel[i]
    //     }
    //     searchData.applyMachine = searchData.applyMachine.split(",")
    //     data.details.forEach((res: any) => {
    //       wlListArray.value.push({
    //         typeIds: typeIds++,
    //         ...res
    //       })
    //     })
    //     macObj.vesselId = e.id
    //     macObj.companyId = e.companyId
    //     dbPageDate.showAdd3 = true
    //   }
    // })
    post({
      url: 'wms/toolVessel/getDetails',
      data: {
        id: e.id,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        post({
          url: 'wms/toolVesselDebit/getMacInfoByCode',
          data: {
            id: e.id,
          },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            macObj.machineCode = data.machineCode
            macObj.machineName = data.machineName
          }
        })
        for (let i in data.toolVessel) {
          searchData[i] = data.toolVessel[i]
        }
        // searchData.applyMachine = searchData.applyMachine.split(",")
        data.details.forEach((res: any) => {
          wlListArray.value.push({
            typeIds: typeIds++,
            ...res,
          })
        })
        macObj.vesselId = e.id
        macObj.companyId = e.companyId
        dbPageDate.titles = '明细'
        booleanAees.value = true
        dbPageDate.showAdd = true
        searchData.needleNumber = 0
        wlListArray.value.forEach(function (o: any) {
          getTotalNum(o)
          searchData.needleNumber += o.totalNum
        })
      }
    })
  }

  const sideOk3 = async () => {
    formRef.value?.validate().then((err: any) => {
      if (!err) {
        post({
          url: 'wms/toolInStock/returnInStock',
          data: {
            stockInfo: {
              inStockType: '车间退料入库',
              companyId: searchData.companyId,
              companyName: searchData.companyName,
              warehouseTypeName: searchData.warehouseTypeName,
              warehouseId: searchData.warehouseId,
              warehouseName: searchData.warehouseName,
              vesselsId: macObj.vesselId,
            },
            addInfo: wlListArray.value,
            deleteInfo: deleteInfo.value,
          },
        }).then(({ code, message }) => {
          if (code == 200) {
            zpCxList()
            for (let item in searchData) {
              searchData[item] = null
            }
            wlListArray.value = []
            deleteInfo.value = []
            dbPageDate.showAdd3 = false
            Message.success('成功')
          } else {
            Message.error(message)
          }
        })
      }
    })
  }

  const sideNo3 = () => {
    for (let item in searchData) {
      searchData[item] = null
    }
    wlListArray.value = []
    deleteInfo.value = []
    dbPageDate.showAdd3 = false
  }

  let getZpId: any = null

  const macObj = reactive({
    machineCode: '',
    machineName: '',
    vesselId: null,
    infoType: 1,
    companyId: null,
    outStockType: '针盘出库',
  })

  const machineNameCode: any = ref([])

  const machineNameCodeCx = (e: any) => {
    if (!e || typeof e === 'object') e = ''
    post({
      url: 'planSingle/machine/getFieldValueWms',
      data: {
        machineCode: e,
        companyId: macObj.companyId,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        machineNameCode.value = data
      }
    })
  }

  const machineNameCodeChange = (e: any) => {
    macObj.machineCode = e.split('-')[0]
    // macObj.machineName = e.split('-')[1]
    const namePattern = /-(.*)$/ // 正则表达式匹配机台名称部分
    const nameMatch = e.match(namePattern)
    if (nameMatch && nameMatch.length > 1) {
      macObj.machineName = nameMatch[1]
    } else {
      macObj.machineName = ''
    }
  }

  const configCascader2 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService2 = new WHService()
  const fhWhList2: any = whService2.whList
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService2.getWarhouseListByFirmId(corporateId, '制具仓')
  }

  const sideOk2 = () => {
    post({
      url: 'wms/toolVessel/repairTool',
      data: {
        toolVessel: { ...searchData },
        updateInfo: wlListArray3.value,
        deleteInfo: minHlisyId,
      },
    }).then(({ code, message }) => {
      if (code == 200) {
        zpCxList()
        for (let item in searchData) {
          searchData[item] = null
        }
        wlListArray3.value = []
        minHlisyId = []
        dbPageDate.showAdd2 = false
        Message.success('成功')
      } else {
        Message.error(message)
      }
    })
  }

  const sideNo2 = () => {
    for (let item in searchData) {
      searchData[item] = null
    }
    wlListArray3.value = []
    minHlisyId = []
    dbPageDate.showAdd2 = false
  }

  const wlListArray4: any = ref([])

  let materObj: any = {}
  let materObj2: any = {}
  let xzNumber: any = ref()
  let minGrady: any = ''
  let minHlisyId: any = []
  const clickBC = (record: any) => {
    xzNumber.value = record.totalNum
    materObj2 = record
    materObj = JSON.parse(JSON.stringify(record))
    delete materObj['grade']
    delete materObj['totalNum']
    delete materObj['id']
    wlListArray4.value.push(JSON.parse(JSON.stringify(materObj)))
    post({
      url: 'wms/toolVessel/getMinGrade',
      data: {
        vesselId: getZpId,
        materialCode: record.materialCode,
      },
    }).then(({ code, data }) => {
      if (code == 200) {
        minGrady = data
        visible.value = true
      }
    })
  }

  const visible = ref(false)
  const handleOk = async () => {
    let getNumber = 0
    wlListArray4.value.forEach((res: any) => {
      getNumber += res.totalNum
    })
    if (getNumber != xzNumber.value) {
      Message.error('数量必须等于' + xzNumber.value)
      return false
    }
    // if (wlListArray4.value.length > 1) {
    //     for (let i = 0; i < wlListArray4.value.length; i++) {
    //         if (wlListArray4.value[i].grade == wlListArray4.value[0].grade) {
    //             Message.error('等级重复')
    //             return false
    //         }
    //     }
    // }
    wlListArray3.value = wlListArray3.value.filter((val: any) => {
      return val != materObj2
    })
    wlListArray3.value.push(...wlListArray4.value)
    minHlisyId.push(materObj2.id)
    wlListArray4.value = []
    xzNumber.value = null
    materObj = {}
    materObj2 = {}
    minGrady = ''
    return true
  }

  const handleCancel = () => {
    visible.value = false
    wlListArray4.value = []
    xzNumber.value = null
    materObj2 = {}
    materObj = {}
    minGrady = ''
  }

  const addLineMcode = () => {
    delete materObj['grade']
    delete materObj['totalNum']
    delete materObj['id']
    wlListArray4.value.push(JSON.parse(JSON.stringify(materObj)))
  }

  const delLine2 = (e: any) => {
    if (wlListArray4.value.length == 1) {
      Message.error('最少保留一条')
      return
    } else {
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: () => {
          wlListArray4.value = wlListArray4.value.filter((val: any) => {
            return val != e
          })
        },
      })
    }
  }

  const gradrList3: any = ref([])

  const gradeChange3 = () => {
    post({
      url: 'dict/dictTypeDetail/getListByMapGrade1',
      data: {
        codeType: 36,
        detailName: minGrady,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList3.value = data
      }
    })
  }
  const deletZps = () => {
    if (tableDataList2.value.length == 0) {
      Message.error('请勾选数据')
      return
    }
    Modal.confirm({
      title: '系统提示',
      content: '确认清空针盘?',
      onOk: () => {
        post({
          url: 'wms/toolVessel/emptyTool',
          data: gridOption2.value.getSelectedRows().map((res: any) => res.id),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('删除成功')
            zpCxList()
          } else Message.error(res.message)
        })
      },
    })
  }
  const scrapNumInput = ($event: any) => {
    if (Number((event as any)?.target.value) > $event['totalNum'] - $event['degraNum']) {
      Message.error('请勿大于原数量')
      $event['scrapNum'] = 0
      return
    }
  }
  const degraNumInput = ($event: any) => {
    if (Number((event as any)?.target.value) > $event['totalNum'] - $event['scrapNum']) {
      Message.error('请勿大于原数量')
      $event['degraNum'] = 0
      return
    }
  }

  /**
   * 导出EXCEL
   */
  const exportExcel = () => {
    let header = tc
      .map((o) => {
        return o.headerName
      })
      .splice(1)
    let filterCols = tc
      .map((c) => {
        return c.field
      })
      .splice(1)
    let data = formatJson(filterCols, tableDataList.value)
    exportStyleExcel({ header, data, filename: '制具仓库存表.xlsx' })
  }

  /**
   * 过滤需要导出的列，并转换数据格式，如STATUS
   */
  const formatJson = (filterVal, jsonData) => {
    return jsonData.map((v) =>
      filterVal.map((j) => {
        if (!v[j]) {
          console.log(v[j])
          return ''
        }
        if (j == 'status') {
          if (v[j] == 1) {
            return '正常'
          } else {
            return '禁用'
          }
        } else {
          if (j) {
            return v[j]
          }
        }
      })
    )
  }

  const visibleYlzj = ref(false)

  const handleOkszj = () => {
    if (selectedRowKeysZp.value.length == 0) {
      Message.error('请勾选数据')
      return false
    }
    wlListArray1.value = []
    if (wlListArray.value.length == 0) {
      wlListArray.value = JSON.parse(
        JSON.stringify(
          wlListZp.value.filter((x: any) => {
            return selectedRowKeysZp.value.includes(x.id)
          })
        )
      )
      wlListArray.value.forEach((res: any) => {
        delete res.id
        res['totalNum1'] = res['totalNum']
        res['totalNum'] = 0
        res['typeIds'] = typeIds++
      })
      // wlListZp.value.forEach((item: any) => {
      //   if (wlListArray.value)
      // })
      postTwoList(wlListArray.value)
      return true
    } else {
      let wlListArray2 = JSON.parse(
        JSON.stringify(
          wlListZp.value.filter((x: any) => {
            return selectedRowKeysZp.value.includes(x.id)
          })
        )
      )
      wlListArray2.forEach((res: any) => {
        delete res.id
        res['totalNum1'] = res['totalNum']
        res['totalNum'] = 0
        res['typeIds'] = typeIds++
      })
      for (let i = 0; i < wlListArray.value.length; i++) {
        let is = wlListArray.value[i]
        for (let j = 0; j < wlListArray2.length; j++) {
          let is2 = wlListArray2[j]
          if (is.materialCode == is2.materialCode && is.grade == is2.grade) {
            Message.error('请勿勾选相同等级物料')
            return false
          }
        }
      }
      wlListArray.value.push(...wlListArray2)
      postTwoList(wlListArray.value)
      return true
    }
  }
  const postTwoList = (val: any) => {
    post({
      url: 'wms/toolVesselDebit/getInfoByCode',
      data: val,
    }).then((res: any) => {
      if (res.code == 200) {
        wlListArray1.value = res.data
      }
    })
  }
  const selectedRowKeysZp = ref([])
  const wlListZp = ref([])
  const cgColumnsZp = [
    {
      dataIndex: 'majorCategory',
      key: 'majorCategory',
      title: '物料大类',
      width: 150,
    },
    {
      dataIndex: 'middleCategory',
      key: 'middleCategory',
      title: '物料中类',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      key: 'subCategory',
      title: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      key: 'materialCode',
      title: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      key: 'materialName',
      title: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      key: 'totalNum',
      title: '数量',
      width: 150,
    },
    {
      dataIndex: 'useNum',
      key: 'useNum',
      title: '针盘使用数量',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位',
      width: 150,
    },
  ]

  const isLyCodedsZp = ref('')
  const isLyNamedsZp = ref('')
  const fySeletZp: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSizeZp = (val: any) => {
    fySeletZp.page = val
    zpKcSelect()
  }

  const changeZp = (val: any) => {
    fySeletZp.size = val
    zpKcSelect()
  }
  const cxZpKc = () => {
    zpKcSelect()
  }
  function zpKcSelect() {
    post({
      url: 'wms/toolStockSummary/getPage',
      data: {
        page: fySeletZp.page,
        size: fySeletZp.size,
        materialCode: isLyCodedsZp.value,
        materialName: isLyNamedsZp.value,
        companyId: searchData.companyId,
        warehouseId: searchData.warehouseId,
      },
    }).then((res: any) => {
      wlListZp.value = res.data.data
      fySeletZp.total = res.data.total
    })
  }
  const changeTot = (val: any) => {
    // console.log(val, '2')
    searchData.needleNumber = 0
    nextTick(() => {
      if (val.totalNum1 - val.useNum < val.totalNum) {
        // nextTick(() => {
        val.totalNum = val.totalNum1 - val.useNum
        // val.totalNum = 0
        Message.error('请勿大于库存可用数量')
        // })
      }
      wlListArray.value.forEach((item: any) => {
        searchData.needleNumber += item.totalNum
      })
    })
  }
  const changeTotA = (val: any) => {
    if (val.subNum > val.totalNum) {
      Message.error('请勿大于原数量')
      val.subNum = 0
    }
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('NventoryManagement3-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('NventoryManagement3-2', gridOption2, colState2, tc2)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('NventoryManagement3-3', gridOption3, colState3, tc3)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }
</script>
